﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace lucere.index.merge
{
    /// <summary>A {@link MergeScheduler} that runs each merge using a
    /// separate thread, up until a maximum number of threads
    /// ({@link #setMaxThreadCount}) at which when a merge is
    /// needed, the thread(s) that are updating the index will
    /// pause until one or more merges completes.  This is a
    /// simple way to use concurrency in the indexing process
    /// without having to create and manage application level
    /// threads. 
    /// </summary>

    public interface IConcurrentMergeScheduler : IMergeScheduler
    {
        /// <summary>Sets/Gets the max # simultaneous threads that may be
        /// running.  If a merge is necessary yet we already have
        /// this many threads running, the incoming thread (that
        /// is calling add/updateDocument) will block until
        /// a merge thread has completed. 
        /// </summary>
        int MaxThreadCount { get; set; }

        /// <summary>Return the priority that merge threads run at.  By
        /// default the priority is 1 plus the priority of (ie,
        /// slightly higher priority than) the first thread that
        /// calls merge. 
        /// </summary>
        int MergeThreadPriority { get; set; }

        bool SuppressExceptions { get; set; }

        void SyncThreads();

        void HandleMergeException(Exception exc);

        bool AnyUnhandledExceptions();
        void ClearUnhandledExceptions();
    }
}
